<?php 
namespace app\admin\service;


use app\admin\model\Posters;
use think\facade\Db;

/**
 * 邀请海报管理-服务类
 * @author 小树林
 * @since: 2023/12/23
 * Class PostersService
 * @package app\admin\service
 */
class PostersService extends BaseService
{
    /**
     * 构造函数
     * LevelService constructor.
     */
    public function __construct()
    {
        $this->model = new Posters();
    }
	
	/**
     * 获取数据列表
     * @return array
     * @since 2023/12/23
     * @author 小树林
     */
    public function getList()
    {
        $param = request()->param();

        //是否为远程搜索查询
        $is_query = $param['_is_query'] ?? '';
        if(!empty($is_query)){
            return parent::query($param);
        }

        // 查询条件
        $map = [];
		

        $field = '*';
        $with = [];
        $sort = '';
        $relust=parent::getList($map,$field,$with,$sort);
        if($relust['count']!=0){
            foreach ($relust['data'] as $key => $item) {

                        $relust['data'][$key]['image'] = IMG_URL.$item['image'];



            }
        }
        return $relust;
    }

	/**
     * 添加或编辑
     * @return array
     * @since 2023/12/23
     * @author 小树林
     */
    public function edit()
    {
        // 参数
        $data = request()->param();
	                    
		// 图片处理
        $image = getter($data, 'image');
        if (!empty($image)) {
            if (strpos($image, "temp") !== false) {
                $data['image'] = save_image($image, 'posters');
            } else {
                $data['image'] = str_replace(IMG_URL, "", $image);
            }
        }
                                                                                                
        return parent::edit($data); // TODO: Change the autogenerated stub
    }

                                    
}